//Chip HR8P506
//Files Encoded UTF-8

#include "App_Main.h"
#include "chip.h"
#include "../LCD/UI.h"
#include "FactoryTest.h"


void App_Init(void)
{
    GPIOConfig();
    HT162X_Init();
	UI_Init();
    // SystemConfig();
    FanCtrlInit();
    Key_init();
    Switch_IOConfig();
    ADInit();

    Factory_main();
}

void App_Main(void)
{
    
    // if(Factory_Check_Enable > 0) Factory_Check_Enable = 0;
    KeyDetection();
    SwitchKey();
    // Lcd_Show_Ctrl(Switch_State);
    // WDT_Clear();
    TempADC_Main();
	UI_Main();

    if(RTD[0].status == Pt_Normal)
    {
        HeatingFanCtrl();
        IgniterCtrl();
        ExhaustFanCtrl();
    }
    else
    {
        IgniterClose;
        HeaterFanClose;
		if(RTD[0].status==Pt_HighTemp)
		{
			ExhaustFanCtrl();
		}
		else 
		{
			 ExhaustFanClose;
		}
       
    }
#if 0
    if(Switch_State != Temp_Shutoff)
    {
        if(lcd_show_config.ShowBit == 0) FanCtrlStop();
        else
        {
            TempADC_Main(); 
            FanCtrlStart();
        }
       
    }
#endif

}

//Tick 10ms
void SysTick_IRQHandler(void)
{
    if(key_param.once1 > 0)
    {
        key_param.once1--;
    }
    
    if((UI_Refresh_Count > 0) && (UI_Refresh_Count < 0xffff)) UI_Refresh_Count++;
    // if(Factory_Check_Enable == 1) ADC_Clock();
    switch_clock();
    // if(Switch_State == Temp_Shutoff) return;

    ADC_Clock();
    FanCtrlClock();
    // Buzzer_clock();
    UI_Ver_Clock();
	LowTempAlarm();
}
